/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CBGUI.java
 *
 * Created on 14/09/2010, 13:48:46
 */
package jogamesuite;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.EnumSet;
import javax.swing.AbstractAction;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import jogamesuite.lib.*;

/**
 *
 * @author Joaquin
 */
public class CEGUI extends javax.swing.JFrame {

    /** Creates new form CBGUI */
    public CEGUI() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.JPanel optionsPanel = new javax.swing.JPanel();
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
        forumType = new javax.swing.JComboBox();
        javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
        backgroundColor = new javax.swing.JComboBox();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        showNames = new javax.swing.JCheckBox();
        showCoords = new javax.swing.JCheckBox();
        javax.swing.JPanel inputPanel = new javax.swing.JPanel();
        javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
        inputText = new javax.swing.JTextArea();
        readButton = new javax.swing.JButton();
        javax.swing.JScrollPane jScrollPane2 = new javax.swing.JScrollPane();
        outputText = new javax.swing.JTextArea();
        clearButton = new javax.swing.JButton();
        copyAllButton = new javax.swing.JButton();
        javax.swing.JPanel previewPanel = new javax.swing.JPanel();
        javax.swing.JScrollPane jScrollPane3 = new javax.swing.JScrollPane();
        previewText = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JOgame Suite Compactador de Espionaje");

        optionsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), java.awt.SystemColor.textText)); // NOI18N

        jLabel1.setText("Foro:");

        forumType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "phpBB", "HTML" }));

        jLabel2.setText("Fondo:");

        backgroundColor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Claro", "Oscuro" }));
        backgroundColor.setSelectedIndex(1);

        jLabel3.setText("Mostrar:");

        showNames.setSelected(true);
        showNames.setText("Nombres");

        showCoords.setText("Coordenadas");

        javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(optionsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(forumType, 0, 175, Short.MAX_VALUE))
                    .addGroup(optionsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(backgroundColor, 0, 175, Short.MAX_VALUE))
                    .addGroup(optionsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(showCoords)
                            .addComponent(showNames))))
                .addContainerGap())
        );

        optionsPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3});

        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(forumType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(backgroundColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(showNames))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(showCoords))
        );

        inputPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Copiar Reporte:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), java.awt.SystemColor.textText)); // NOI18N

        inputText.setColumns(20);
        inputText.setFont(new java.awt.Font("Monospaced", 0, 12));
        inputText.setRows(5);
        jScrollPane1.setViewportView(inputText);

        readButton.setAction(new ReadAction());
        readButton.setText("Leer");

        outputText.setColumns(20);
        outputText.setFont(new java.awt.Font("Monospaced", 0, 12));
        outputText.setRows(5);
        jScrollPane2.setViewportView(outputText);

        clearButton.setAction(new ClearAllAction());
        clearButton.setText("Borrar Todo");

        copyAllButton.setAction(new SelectAndCopyAction());
        copyAllButton.setText("Seleccionar todo y Copiar");

        javax.swing.GroupLayout inputPanelLayout = new javax.swing.GroupLayout(inputPanel);
        inputPanel.setLayout(inputPanelLayout);
        inputPanelLayout.setHorizontalGroup(
            inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(inputPanelLayout.createSequentialGroup()
                        .addComponent(readButton, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(copyAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE))
                .addContainerGap())
        );

        inputPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {clearButton, readButton});

        inputPanelLayout.setVerticalGroup(
            inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(readButton)
                    .addComponent(clearButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(copyAllButton)
                .addContainerGap())
        );

        previewPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Vista Previa:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), java.awt.SystemColor.textText)); // NOI18N

        jScrollPane3.setBorder(null);

        previewText.setBackground(java.awt.SystemColor.control);
        previewText.setBorder(null);
        previewText.setContentType("text/html");
        previewText.setEditable(false);
        jScrollPane3.setViewportView(previewText);

        javax.swing.GroupLayout previewPanelLayout = new javax.swing.GroupLayout(previewPanel);
        previewPanel.setLayout(previewPanelLayout);
        previewPanelLayout.setHorizontalGroup(
            previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(previewPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
                .addContainerGap())
        );
        previewPanelLayout.setVerticalGroup(
            previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(previewPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 587, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(optionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(inputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(previewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(previewPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(inputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            // Set System L&F
            UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
        } catch (ClassNotFoundException e) {
            // handle exception
        } catch (InstantiationException e) {
            // handle exception
        } catch (IllegalAccessException e) {
            // handle exception
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CEGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox backgroundColor;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton copyAllButton;
    private javax.swing.JComboBox forumType;
    private javax.swing.JTextArea inputText;
    private javax.swing.JTextArea outputText;
    private javax.swing.JTextPane previewText;
    private javax.swing.JButton readButton;
    private javax.swing.JCheckBox showCoords;
    private javax.swing.JCheckBox showNames;
    // End of variables declaration//GEN-END:variables

    private class ReadAction extends AbstractAction {

        public ReadAction() {
            super("Leer");
        }

        public void actionPerformed(ActionEvent evt) {
            SpyReportReader reader;
            try {
                reader = new SpyReportReader(inputText.getText());
            } catch (Exception ex) {
                ex.printStackTrace();
                outputText.setText("Reporte inválido\n" + ex.getMessage());
                return;
            }
            SpyReportWriter writer = new SpyReportWriter(reader);
            outputText.setText(writer.writeReport(forumType.getSelectedIndex()));

            switch (backgroundColor.getSelectedIndex()) {
                case ForumFormatter.COLOR_DARK:
                    previewText.setBackground(Color.DARK_GRAY);
                    previewText.setText("<font face = \"Tahoma\" color=\"#E6E6E6\" >"
                            + writer.writeReport(ForumFormatter.HTML_CODE)
                            + "<font>");
                    break;
                case ForumFormatter.COLOR_LIGHT:
                    previewText.setBackground(Color.LIGHT_GRAY);
                    previewText.setText("<font face = \"Tahoma\" color=\"#0B0B0B\" >"
                            + writer.writeReport(ForumFormatter.HTML_CODE)
                            + "<font>");
                    break;
                default:
                    previewText.setBackground(Color.DARK_GRAY);
                    previewText.setText("<font face = \"Tahoma\" color=\"#E6E6E6\" >"
                            + writer.writeReport(ForumFormatter.HTML_CODE)
                            + "<font>");
            }
        }
    }

    private class ClearAllAction extends AbstractAction {

        public ClearAllAction() {
            super("Borrar todo");
        }

        public void actionPerformed(ActionEvent e) {
            inputText.setText("");
            outputText.setText("");
            previewText.setText("");
        }
    }

    private class SelectAndCopyAction extends AbstractAction {

        public SelectAndCopyAction() {
            super("Seleccionar y copiar todo");
        }

        public void actionPerformed(ActionEvent e) {
            outputText.grabFocus();
            outputText.selectAll();
            outputText.copy();
        }
    }

    private class SpyReportWriter extends ForumWriter {

        final private SpyReportReader reader;
        private Integer[] posibleDebris = new Integer[2];

        SpyReportWriter(SpyReportReader reader) {
            super(forumType.getSelectedIndex(), backgroundColor.getSelectedIndex());
            this.reader = reader;
            getPosibleDebris();
        }

        private void getPosibleDebris() {
            posibleDebris[0] = 0;
            posibleDebris[1] = 0;
            if (!(reader.getFleet() == null)) {
                long f[] = reader.getFleet();
                for (ShipType n : EnumSet.range(ShipType.NAVE_PEQUEÑA_CARGA, ShipType.ACORAZADO)) {
                        posibleDebris[0] += (int) (f[n.ordinal()] * n.getCost()[0] * 0.3);
                        posibleDebris[1] += (int) (f[n.ordinal()] * n.getCost()[1] * 0.3);
                }
            }
        }

        public String writeReport(int codeType) {
            setCodeType(codeType);
            return writeReport();
        }

        public String writeReport() {
            String r = "";
            r += writeReportHeader();
            r += writeResourcesSummary();
            r += writeFleetSummary();
            r += writeDefenceSummary();
            r += writeBuildingSummary();
            r += writeTechnologySummary();
            r += writeProfitSummary();
            r += writeReportFooter();
            return r;
        }

        private String writeReportHeader() {
            String name;
            String coord;
            String planet;
            if (showCoords.isSelected()) {
                coord = reader.getCoord().toString();
            } else {
                coord = "[XX:XXX:XX]";
            }
            if (showNames.isSelected()) {
                name = reader.getPlayerName();
                planet = reader.getPlanetName();
            } else {
                name = "XXXXXXXX";
                planet = "XXXXXX";
            }
            DateFormat dateFormat = DateFormat.getDateInstance();
            DateFormat timeFormat = DateFormat.getTimeInstance();
            Date d = reader.getDate();
            String dStr = "";
            String hStr = "";
            try { // Workarround para problemas en win7 con el formato de fechas
                dStr = dateFormat.format(d);
                hStr = timeFormat.format(d);
            } catch (Exception e) {
                dStr = "desconocido";
                hStr = "hora desconocida";
            }
            String s = "Informe de espionaje de "
                    + tagColor("'" + name + "'", color[2])
                    + " el día "
                    + tagColor(dStr, color[6])
                    + " a las "
                    + tagColor(hStr, color[6])
                    + " (hora server):" + NL + NL;
            s = tagHeader(s);
            String t = "Planeta: "
                    + tagName("'" + planet + "' ", color[2])
                    + tagName(coord, color[1]);
            t = tagTitle(t);
            return s + t + NL + NL;
        }

        private String writeResourcesSummary() {
            long[] recursos = reader.getResources();
            String s = "";
            s += tagTitle2("Recursos") + NL;
            s += "Metal: "
                    + tagColoredNumber(recursos[0], color[3]) + NL;
            s += "Cristal: "
                    + tagColoredNumber(recursos[1], color[3]) + NL;
            s += "Deuterio: "
                    + tagColoredNumber(recursos[2], color[3]) + NL;
            s = tagFontSize(s, 12);
            s += NL + NL;
            return s;
        }

        private String writeItemQuantity(String item, long quantity) {
            String s = "";
            s += item + " "
                    + tagColor(integerFormat.format(quantity), color[2])
                    + NL;
            return s;
        }

        private String writeFleetSummary() {
            String s = "";
            String h = "";
            h += tagTitle2("Escuadrón") + NL;
            if (reader.hasFleetData()) {
                if (reader.hasFleet()) {
                    long[] fleet = reader.getFleet();
                    for (ShipType n : EnumSet.range(ShipType.NAVE_PEQUEÑA_CARGA, ShipType.ACORAZADO)) {
                        if ((fleet[n.ordinal()] != 0)) {
                            s += writeItemQuantity(n.getName(), fleet[n.ordinal()]);
                        }
                    }
                } else {
                    s += tagInfoMessageColor("-Sin Flota-", color[9]) + NL;
                }
            } else {
                s += tagInfoMessageColor("-Sin Datos de Flota-", color[8]) + NL;
            }
            s = tagItalic(s);
            s += NL;
            return h + s;
        }

        private String writeDefenceSummary() {
            String s = "";
            String h = "";
            h += tagTitle2("Defensa") + NL;
            if (reader.hasDefenceData()) {
                if (reader.hasDefence()) {
                    long[] fleet = reader.getFleet();
                    for (ShipType n : EnumSet.range(ShipType.LANZAMISILES, ShipType.MISIL_INTERPLANETARIO)) {
                        if ((fleet[n.ordinal()] != 0)) {
                            s += writeItemQuantity(n.getName(), fleet[n.ordinal()]);
                        }
                    }
                } else {
                    s += tagInfoMessageColor("-Sin Defensas-", color[9]) + NL;
                }
            } else {
                s += tagInfoMessageColor("-Sin Datos de Defensa-", color[8]) + NL;
            }
            s = tagItalic(s);
            s += NL;
            return h + s;
        }

        private String writeBuildingSummary() {
            String s = "";
            String h = "";
            h += tagTitle2("Edificios") + NL;
            if (reader.hasBuildingData()) {
                if (reader.hasBuildings()) {
                    long[] building = reader.getBuilding();
                    for (Building e : Building.values()) {
                        if (building[e.ordinal()] != 0) {
                            s += writeItemQuantity(e.getName(), building[e.ordinal()]);
                        }
                    }
                } else {
                    s += tagInfoMessageColor("-Sin Edificios-", color[9]) + NL;
                }
            } else {
                s += tagInfoMessageColor("-Sin Datos de Edificios-", color[8]) + NL;
            }
            s = tagItalic(s);
            s += NL;
            return h + s;
        }

        private String writeTechnologySummary() {
            String s = "";
            String h = "";
            h += tagTitle2("Tecnologías") + NL;
            if (reader.hasTechnologyData()) {
                if (reader.hasTechnology()) {
                    long[] technology = reader.getTechnology();
                    for (Technology t : Technology.values()) {
                        if (technology[t.ordinal()] != 0) {
                            s += writeItemQuantity(t.getName(), technology[t.ordinal()]);
                        }
                    }
                } else {
                    s += tagInfoMessageColor("-Sin Tecnologías-", color[9]) + NL;
                }
            } else {
                s += tagInfoMessageColor("-Sin Datos de Tecnologías-", color[8]) + NL;
            }
            s = tagItalic(s);
            s += NL;
            return h + s;
        }

        private String writeProfitSummary() {
            long[] recursos = reader.getResources();
            String s = "";
            long[] robo = new long[4];
            robo[3] = 0;
            for (int i = 0; i < recursos.length; i++) {
                robo[i] = recursos[i] / 2;
                robo[3] += robo[i];
            }
            long ngcCount = robo[3] / 25000;
            if (robo[3] % 25000 != 0) {
                ngcCount++;
            }
            // Posible Robo
            s += tagTitle2("Robo teórico:") + NL;
            s += "Metal: "
                    + tagColoredNumber(robo[0], color[2]) + NL
                    + "Cristal: "
                    + tagColoredNumber(robo[1], color[2]) + NL
                    + "Deuterio: "
                    + tagColoredNumber(robo[2], color[2]) + NL;
            s += "Total: "
                    + tagColoredNumber(robo[3], color[5])
                    + " unidades "
                    + "(" + integerFormat.format(ngcCount) + " Naves Grandes de Carga)" + NL;
            s += NL;
            // Posibles Escombros
            s += tagTitle2("Escombros Posibles: ") + NL;
            s += "Metal: "
                    + tagColoredNumber(posibleDebris[0], color[2]) + NL
                    + "Cristal: "
                    + tagColoredNumber(posibleDebris[1], color[2]) + NL;
            int numReciclers = (posibleDebris[0] + posibleDebris[1]) / 20000;
            if ((posibleDebris[0] + posibleDebris[1]) % 20000 != 0) {
                numReciclers++;
            }
            s += "Total: "
                    + tagColoredNumber(posibleDebris[0] + posibleDebris[1], color[5])
                    + " unidades "
                    + "(" + integerFormat.format(numReciclers) + " Recicladores)" + NL;
            s += NL;
            // Máxima Renta posible
            s += tagTitle2("Renta máxima posible (Reciclada + Robo):") + NL;
            s += "Metal: "
                    + tagColoredNumber(robo[0] + posibleDebris[0], color[2]) + NL
                    + "Cristal: "
                    + tagColoredNumber(robo[1] + posibleDebris[1], color[2]) + NL
                    + "Deuterio: "
                    + tagColoredNumber(robo[2], color[2]) + NL;
            s += NL;
            return s;
        }

        private String writeReportFooter() {
            String s = "Reporte compactado por ";
            s += tagURL("http://code.google.com/p/jogamesuite/", "JOgame Suite") + NL;
            return tagFooter(s);
        }
    }
}
